/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements.  See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


/*************************************************************************
 *\author: starlove
 *************************************************************************/
#ifndef __CC_PYTHON_IMPORT_O_MENU_IMPL__
#define __CC_PYTHON_IMPORT_O_MENU_IMPL__

#include "python_object_menu.h"
#include "python_object_touch.h"
NS_CCPY_BEGIN
	//////////////////////////////////////////////////////////
	
	CCLAYER_OBJECT_WRAPPER_IMPL(CCMenu, CPyMenu)	

	PYCLASS_INIT_AND_BASE(CPyMenu, CPyLayerRGBA, "CCMenu", "Python CCMenu Object");
	PYCLASS_BEGIN_METHOD_DEF(CPyMenu)
		PYCLASS_ADD_METHOD(CPyMenu, alignItemsVertically)
		PYCLASS_ADD_METHOD(CPyMenu, alignItemsVerticallyWithPadding)
		PYCLASS_ADD_METHOD(CPyMenu, alignItemsHorizontally)
		PYCLASS_ADD_METHOD(CPyMenu, alignItemsHorizontallyWithPadding)
		PYCLASS_ADD_METHOD(CPyMenu, alignItemsInColumns)
		PYCLASS_ADD_METHOD(CPyMenu, alignItemsInRows)
	PYCLASS_END_METHOD_DEF(CPyMenu)
	PYCLASS_BEGIN_GETSET_DEF(CPyMenu)
		PYCLASS_ADD_SET(CPyMenu, HandlerPriority)
	PYCLASS_END_GETSET_DEF(CPyMenu)
	PYCLASS_IMP_INTERFACE_NEW(CPyMenu)
	
	void CPyMenu::__del__(CPyMenu *self)
	{
		CCLog("[PYTHON] >>> [DELETE] CPyMenu");
		self->ob_type->tp_free(self);
	}

	int CPyMenu::__init__(CPyMenu *pySelf, PyObject *pyArgs, PyObject *pyKW)
	{
		if( !pyArgs )
			return 0;
		static char* kwlist[] = {"items", NULL};
		PyObject *items = NULL;
		if(!PyArg_ParseTupleAndKeywords(pyArgs,pyKW,"O",kwlist, &items))
			return 0;
		if(!items || !PySequence_Check(items))
			return 0;
		cocos2d::CCArray *arr = CCPyDataConvert::CCArrayFromPyList(items);
		cocos2d::CCMenu *menu = dynamic_cast<cocos2d::CCMenu *>(pySelf->getCCObject());
		if(!menu)
			return 0;
		menu->initWithArray(arr);
		return 0;
	}
		
	PYCLASS_METHOD_IMPL(CPyMenu, alignItemsVertically)
	{
		cocos2d::CCMenu *menu = dynamic_cast<cocos2d::CCMenu *>(pySelf->getCCObject());
		if(!menu)
			Py_RETURN_NONE;
		menu->alignItemsVertically();
		Py_RETURN_NONE;
	}
		
	PYCLASS_METHOD_IMPL(CPyMenu, alignItemsVerticallyWithPadding)
	{
		float f = 0;
		if( !PyArg_ParseTuple(pyArgs, "f", &f) )
			Py_RETURN_NONE;
		cocos2d::CCMenu *menu = dynamic_cast<cocos2d::CCMenu *>(pySelf->getCCObject());
		if(!menu)
			Py_RETURN_NONE;
		menu->alignItemsVerticallyWithPadding(f);
		Py_RETURN_NONE;
	}
		
	PYCLASS_METHOD_IMPL(CPyMenu, alignItemsHorizontally)
	{
		cocos2d::CCMenu *menu = dynamic_cast<cocos2d::CCMenu *>(pySelf->getCCObject());
		if(!menu)
			Py_RETURN_NONE;
		menu->alignItemsHorizontally();
		Py_RETURN_NONE;
	}
		
	PYCLASS_METHOD_IMPL(CPyMenu, alignItemsHorizontallyWithPadding)
	{
		float f = 0;
		if( !PyArg_ParseTuple(pyArgs, "f", &f) )
			Py_RETURN_NONE;
		cocos2d::CCMenu *menu = dynamic_cast<cocos2d::CCMenu *>(pySelf->getCCObject());
		if(!menu)
			Py_RETURN_NONE;
		menu->alignItemsHorizontallyWithPadding(f);
		Py_RETURN_NONE;
	}
	
	PYCLASS_METHOD_IMPL(CPyMenu, alignItemsInColumns)
	{
		PyObject *items = 0;
		if( !PyArg_ParseTuple(pyArgs, "O", &items) )
			Py_RETURN_NONE;
		cocos2d::CCArray *arr = CCPyDataConvert::CCIntArrayFromPyList(items);
		cocos2d::CCMenu *menu = dynamic_cast<cocos2d::CCMenu *>(pySelf->getCCObject());
		if(!menu)
			Py_RETURN_NONE;
		menu->alignItemsInColumnsWithArray(arr);
		Py_RETURN_NONE;
	}
	
	PYCLASS_METHOD_IMPL(CPyMenu, alignItemsInRows)
	{
		PyObject *items = 0;
		if( !PyArg_ParseTuple(pyArgs, "O", &items) )
			Py_RETURN_NONE;
		cocos2d::CCArray *arr = CCPyDataConvert::CCIntArrayFromPyList(items);
		cocos2d::CCMenu *menu = dynamic_cast<cocos2d::CCMenu *>(pySelf->getCCObject());
		if(!menu)
			Py_RETURN_NONE;
		menu->alignItemsInRowsWithArray(arr);
		Py_RETURN_NONE;
	}
		
	PYCLASS_SET_IMPL(CPyMenu, HandlerPriority)
	{
		cocos2d::CCMenu *menu = dynamic_cast<cocos2d::CCMenu *>(pySelf->getCCObject());
		if(menu)
			menu->setHandlerPriority(PyLong_AsLong(pyValue));
		return 0;
	}
	//////////////////////////////////////////////////////////	
	CC_MENUITEM_WRAPPER_IMPL(CCMenuItem, CPyMenuItem)	

	PYCLASS_INIT_AND_BASE(CPyMenuItem, CPyNodeRGBA, "CCMenuItem", "Python CCMenuItem Object");
	PYCLASS_BEGIN_METHOD_DEF(CPyMenuItem)
	PYCLASS_ADD_METHOD(CPyMenuItem, activate)
	PYCLASS_ADD_METHOD(CPyMenuItem, selected)
	PYCLASS_ADD_METHOD(CPyMenuItem, unselected)
	PYCLASS_END_METHOD_DEF(CPyMenuItem)
	PYCLASS_BEGIN_GETSET_DEF(CPyMenuItem)
	PYCLASS_ADD_GET(CPyMenuItem, rect)
	PYCLASS_ADD_GET(CPyMenuItem, Selected)
	PYCLASS_ADD_SET(CPyMenuItem, Target)
	PYCLASS_END_GETSET_DEF(CPyMenuItem)
	PYCLASS_IMP_INTERFACE_NEW(CPyMenuItem)
	
	PYCLASS_METHOD_IMPL(CPyMenuItem, activate)
	{
		CC_METHOD_WRAPPER_SETER(cocos2d::CCMenuItem *, CPyMenuItem, activate);
		Py_RETURN_NONE;
	}
	PYCLASS_METHOD_IMPL(CPyMenuItem, selected)
	{
		CC_METHOD_WRAPPER_SETER(cocos2d::CCMenuItem *, CPyMenuItem, selected);
		Py_RETURN_NONE;
	}
	PYCLASS_METHOD_IMPL(CPyMenuItem, unselected)
	{
		CC_METHOD_WRAPPER_SETER(cocos2d::CCMenuItem *, CPyMenuItem, unselected);
		Py_RETURN_NONE;
	}
	PYCLASS_GET_IMPL(CPyMenuItem, rect)
	{
		CC_METHOD_WRAPPER_GETER(cocos2d::CCMenuItem *, CPyMenuItem, rect, cocos2d::CCRect);
		PyObject *p = (PyObject *)CPyRect::create(v);
		return p;
	}
	PYCLASS_GET_IMPL(CPyMenuItem, Selected)
	{
		CC_METHOD_WRAPPER_GETER(cocos2d::CCMenuItem *, CPyMenuItem, isSelected, bool);
		Py_RETURN_BOOL(v);
	}
	PYCLASS_SET_IMPL(CPyMenuItem, Target)
	{
		if(!PyCallable_Check(pyValue))
			return 0;
		pySelf->setFn(pyValue);
		CC_METHOD_WRAPPER_SETER_RINT(cocos2d::CCMenuItem *, CPyMenuItem, setTarget, pySelf->getCCObject(), __menu_selector(__CCMenuItemWrapper::OnClick));
		return 0;
	}
	
	int CPyMenuItem::__init__(CPyMenuItem *pySelf, PyObject *pyArgs, PyObject *pyKW)
	{
		if( !pyArgs )
			return 0;
		static char* kwlist[] = {"func", NULL};
		PyObject *func = NULL;
		if(!PyArg_ParseTupleAndKeywords(pyArgs,pyKW,"O",kwlist, &func))
			return 0;
		if(!func || !PyCallable_Check(func))
			return 0;
		cocos2d::CCMenuItem *item = dynamic_cast<cocos2d::CCMenuItem *>(pySelf->getCCObject());
		if(!item)
			return 0;
		pySelf->setFn(func, false);
		item->initWithTarget(item, __menu_selector(__CCMenuItemWrapper::OnClick));
		return 0;
	}
	
	void CPyMenuItem::__del__(CPyMenuItem *self)
	{
		self->freeFn();
		self->ob_type->tp_free(self);
	}

	//////////////////////////////////////////////////////////	
	CC_MENUITEM_WRAPPER_IMPL(CCMenuItemLabel, CPyMenuItemLabel)

	PYCLASS_INIT_AND_BASE(CPyMenuItemLabel, CPyMenuItem, "CCMenuItemLabel", "Python CCMenuItemLabel Object");
	PYCLASS_BEGIN_METHOD_DEF(CPyMenuItemLabel)
	PYCLASS_ADD_METHOD(CPyMenuItemLabel, setString)
	PYCLASS_END_METHOD_DEF(CPyMenuItemLabel)
	PYCLASS_BEGIN_GETSET_DEF(CPyMenuItemLabel)
	PYCLASS_ADD_GETSET(CPyMenuItemLabel, DisabledColor)
	PYCLASS_ADD_GETSET(CPyMenuItemLabel, Label)
	PYCLASS_END_GETSET_DEF(CPyMenuItemLabel)
	PYCLASS_IMP_INTERFACE_NEW(CPyMenuItemLabel)
	
	void CPyMenuItemLabel::__del__(CPyMenuItemLabel *self)
	{
		self->freeFn();
		self->ob_type->tp_free(self);
	}
		
	PYCLASS_METHOD_IMPL(CPyMenuItemLabel, setString)
	{
		char *s = NULL;
		if( !PyArg_ParseTuple(pyArgs, "s", &s) )
			Py_RETURN_NONE;
		if(!s)
			Py_RETURN_NONE;
		CC_METHOD_WRAPPER_SETER(cocos2d::CCMenuItemLabel *, CPyMenuItemLabel, setString, s);
		Py_RETURN_NONE;
	}
	PYCLASS_GET_IMPL(CPyMenuItemLabel, DisabledColor)
	{
		CC_METHOD_WRAPPER_GETER(cocos2d::CCMenuItemLabel *, CPyMenuItemLabel, getDisabledColor, cocos2d::ccColor3B);
		return (PyObject *)CPyColor3B::create(v);
	}
	PYCLASS_SET_IMPL(CPyMenuItemLabel, DisabledColor)
	{
		if(!PyObject_TypeCheck(pyValue, CPyClassBase::GetTypeObject<CPyColor3B>()))
			return 0;
		CPyColor3B *p = (CPyColor3B *)pyValue;
		CC_METHOD_WRAPPER_SETER_RINT(cocos2d::CCMenuItemLabel *, CPyMenuItemLabel, setDisabledColor, p->getCCObject());
		return 0;
	}
	PYCLASS_GET_IMPL(CPyMenuItemLabel, Label)
	{
		CC_METHOD_WRAPPER_GETER(cocos2d::CCMenuItemLabel *, CPyMenuItemLabel, getLabel, cocos2d::CCNode *);
		IWrapper *wrap = dynamic_cast<IWrapper *>(v);
		PyObject *p = Py_None;
		if(wrap)
		{
			p = CPyCCObject::create_object(wrap->GetPythonType(), v);
		}else
			p = (PyObject *)CPyCCObject::create<CPyCCObject>(v);
		return p;
	}
	PYCLASS_SET_IMPL(CPyMenuItemLabel, Label)
	{
		CPyCCObject *p = (CPyCCObject *)pyValue;
		IWrapper *wrap = dynamic_cast<IWrapper *>(p->getCCObject());
		if(!wrap)
			return 0;
			CC_METHOD_WRAPPER_SETER_RINT(cocos2d::CCMenuItemLabel *, CPyMenuItemLabel, setLabel, (cocos2d::CCNode *)p->getCCObject());
		return 0;
	}
	
	int CPyMenuItemLabel::__init__(CPyMenuItemLabel *pySelf, PyObject *pyArgs, PyObject *pyKW)
	{
		if( !pyArgs )
			return 0;
		static char* kwlist[] = {"label", "func", NULL};
		PyObject *label = NULL;
		PyObject *func = NULL;
		if(!PyArg_ParseTupleAndKeywords(pyArgs,pyKW,"O|O",kwlist, &label, &func))
			return 0;
		
		CPyCCObject *p = (CPyCCObject *)label;
		IWrapper *wrap = dynamic_cast<IWrapper *>(p->getCCObject());
		if(!wrap)
			return 0;

		if(func && !PyCallable_Check(func))
			return 0;

		cocos2d::CCMenuItemLabel *item = dynamic_cast<cocos2d::CCMenuItemLabel *>(pySelf->getCCObject());
		if(!item)
			return 0;
		if(func)
		{
			pySelf->setFn(func, false);
			item->initWithLabel((cocos2d::CCNode *)p->getCCObject(), item, __menu_selector(__CCMenuItemLabelWrapper::OnClick));
		}else
			item->initWithLabel((cocos2d::CCNode *)p->getCCObject(), NULL, NULL);
		return 0;
	}
	//////////////////////////////////////////////////////////	
	CC_MENUITEM_WRAPPER_IMPL(CCMenuItemAtlasFont, CPyMenuItemAtlasFont)

	PYCLASS_INIT_AND_BASE(CPyMenuItemAtlasFont, CPyMenuItemLabel, "CCMenuItemAtlasFont", "Python CCMenuItemAtlasFont Object");
	PYCLASS_BEGIN_METHOD_DEF(CPyMenuItemAtlasFont)
	PYCLASS_END_METHOD_DEF(CPyMenuItemAtlasFont)
	PYCLASS_BEGIN_GETSET_DEF(CPyMenuItemAtlasFont)
	PYCLASS_END_GETSET_DEF(CPyMenuItemAtlasFont)
	PYCLASS_IMP_INTERFACE_NEW(CPyMenuItemAtlasFont)

	void CPyMenuItemAtlasFont::__del__(CPyMenuItemAtlasFont *self)
	{
		self->freeFn();
		self->ob_type->tp_free(self);
	}
	
	int CPyMenuItemAtlasFont::__init__(CPyMenuItemAtlasFont *pySelf, PyObject *pyArgs, PyObject *pyKW)
	{
		if( !pyArgs )
			return 0;
		
		static char* kwlist[] = {"value", "charMapFile", "itemWidth", "itemHeight", "startCharMap", "func", NULL};
		char *value = NULL;
		char *charMapFile = NULL;
		int itemWidth = 0;
		int itemHeight = 0;
		int startCharMap = 0;
		PyObject *func = NULL;
		if(!PyArg_ParseTupleAndKeywords(pyArgs,pyKW,"ssiii|O",kwlist, &value, &charMapFile, &itemWidth, &itemHeight, &startCharMap, &func))
			return 0;
		
		if(func && !PyCallable_Check(func))
			return 0;

		cocos2d::CCMenuItemAtlasFont *item = dynamic_cast<cocos2d::CCMenuItemAtlasFont *>(pySelf->getCCObject());
		if(!item)
			return 0;
		if(func)
		{
			pySelf->setFn(func, false);
			item->initWithString(value, charMapFile, itemWidth, itemHeight, (char)startCharMap, item, __menu_selector(__CCMenuItemAtlasFontWrapper::OnClick));
		}else
			item->initWithString(value, charMapFile, itemWidth, itemHeight, (char)startCharMap, NULL, NULL);
		return 0;
	}
	//////////////////////////////////////////////////////////	
	CC_MENUITEM_WRAPPER_IMPL(CCMenuItemFont, CPyMenuItemFont)

	PYCLASS_INIT_AND_BASE(CPyMenuItemFont, CPyMenuItemLabel, "CCMenuItemFont", "Python CCMenuItemFont Object");
	PYCLASS_BEGIN_METHOD_DEF(CPyMenuItemFont)
		PYCLASS_ADD_METHOD_EX(CPyMenuItemFont, setDefaultFontSize	, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyMenuItemFont, getDefaultFontSize	, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyMenuItemFont, setDefaultFontName	, METH_STATIC|METH_VARARGS)
		PYCLASS_ADD_METHOD_EX(CPyMenuItemFont, getDefaultFontName	, METH_STATIC|METH_VARARGS)
	PYCLASS_END_METHOD_DEF(CPyMenuItemFont)
	PYCLASS_BEGIN_GETSET_DEF(CPyMenuItemFont)
		PYCLASS_ADD_GETSET(CPyMenuItemFont, FontSize)
		PYCLASS_ADD_GETSET(CPyMenuItemFont, FontName)
	PYCLASS_END_GETSET_DEF(CPyMenuItemFont)
	PYCLASS_IMP_INTERFACE_NEW(CPyMenuItemFont)
		
	void CPyMenuItemFont::__del__(CPyMenuItemFont *self)
	{
		self->freeFn();
		self->ob_type->tp_free(self);
	}

	int CPyMenuItemFont::__init__(CPyMenuItemFont *pySelf, PyObject *pyArgs, PyObject *pyKW)
	{
		if( !pyArgs )
			return 0;
		
		static char* kwlist[] = {"value", "func", NULL};
		char *value = NULL;
		char *charMapFile = NULL;
		int itemWidth = 0;
		int itemHeight = 0;
		int startCharMap = 0;
		PyObject *func = NULL;
		if(!PyArg_ParseTupleAndKeywords(pyArgs,pyKW,"s|O",kwlist, &value, &func))
			return 0;
		
		if(func && !PyCallable_Check(func))
			return 0;

		cocos2d::CCMenuItemFont *item = dynamic_cast<cocos2d::CCMenuItemFont *>(pySelf->getCCObject());
		if(!item)
			return 0;
		if(func)
		{
			pySelf->setFn(func, false);
			item->initWithString(value, item, __menu_selector(__CCMenuItemFontWrapper::OnClick));
		}else
			item->initWithString(value, NULL, NULL);
		return 0;
	}
	PYCLASS_METHOD_IMPL(CPyMenuItemFont, setDefaultFontSize)
	{
		unsigned int s = 0;
		if( !PyArg_ParseTuple(pyArgs, "I", &s) )
			Py_RETURN_NONE;
		cocos2d::CCMenuItemFont::setFontSize(s);
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyMenuItemFont, getDefaultFontSize)
	{
		unsigned int s = cocos2d::CCMenuItemFont::fontSize();
		return Py_BuildValue("I",s);
	}

	PYCLASS_METHOD_IMPL(CPyMenuItemFont, setDefaultFontName)
	{
		char *s = NULL;
		if( !PyArg_ParseTuple(pyArgs, "s", &s) )
			Py_RETURN_NONE;
		cocos2d::CCMenuItemFont::setFontName(s);
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyMenuItemFont, getDefaultFontName)
	{
		const char *s = cocos2d::CCMenuItemFont::fontName();
		return Py_BuildValue("s",s);
	}

	PYCLASS_GET_IMPL(CPyMenuItemFont, FontSize)
	{
		cocos2d::CCMenuItemFont *item = (cocos2d::CCMenuItemFont *)pySelf->getCCObject();
		unsigned int s = item->fontSizeObj();
		return Py_BuildValue("I",s);
	}

	PYCLASS_SET_IMPL(CPyMenuItemFont, FontSize)
	{
		cocos2d::CCMenuItemFont *item = (cocos2d::CCMenuItemFont *)pySelf->getCCObject();
		item->setFontSizeObj(PyLong_AsUnsignedLong(pyValue));
		return 0;
	}

	PYCLASS_GET_IMPL(CPyMenuItemFont, FontName)
	{
		cocos2d::CCMenuItemFont *item = (cocos2d::CCMenuItemFont *)pySelf->getCCObject();
		const char *s = item->fontNameObj();
		return Py_BuildValue("s",s);
	}

	PYCLASS_SET_IMPL(CPyMenuItemFont, FontName)
	{
		cocos2d::CCMenuItemFont *item = (cocos2d::CCMenuItemFont *)pySelf->getCCObject();
		item->setFontNameObj(PyString_AsString(pyValue));
		return 0;
	}
	//////////////////////////////////////////////////////////	
	CC_MENUITEM_WRAPPER_IMPL(CCMenuItemSprite, CPyMenuItemSprite)

	PYCLASS_INIT_AND_BASE(CPyMenuItemSprite, CPyMenuItem, "CCMenuItemSprite", "Python CCMenuItemSprite Object");
	PYCLASS_BEGIN_METHOD_DEF(CPyMenuItemSprite)
	PYCLASS_END_METHOD_DEF(CPyMenuItemSprite)
	PYCLASS_BEGIN_GETSET_DEF(CPyMenuItemSprite)
	PYCLASS_ADD_GETSET(CPyMenuItemSprite, NormalImage)
	PYCLASS_ADD_GETSET(CPyMenuItemSprite, SelectedImage)
	PYCLASS_ADD_GETSET(CPyMenuItemSprite, DisabledImage)
	PYCLASS_END_GETSET_DEF(CPyMenuItemSprite)
	PYCLASS_IMP_INTERFACE_NEW(CPyMenuItemSprite)

	void CPyMenuItemSprite::__del__(CPyMenuItemSprite *self)
	{
		self->freeFn();
		self->ob_type->tp_free(self);
	}

	PYCLASS_GET_IMPL(CPyMenuItemSprite, NormalImage)
	{
		CC_METHOD_WRAPPER_GETER(cocos2d::CCMenuItemSprite *, CPyMenuItemSprite, getNormalImage, cocos2d::CCNode *);
		IWrapper *wrap = dynamic_cast<IWrapper *>(v);
		PyObject *p = Py_None;
		if(wrap)
		{
			p = CPyCCObject::create_object(wrap->GetPythonType(), v);
		}else
			p = (PyObject *)CPyCCObject::create<CPyCCObject>(v);
		return p;
	}
	PYCLASS_SET_IMPL(CPyMenuItemSprite, NormalImage)
	{
		CPyCCObject *p = (CPyCCObject *)pyValue;
		IWrapper *wrap = dynamic_cast<IWrapper *>(p->getCCObject());
		if(!wrap)
			return 0;
			CC_METHOD_WRAPPER_SETER_RINT(cocos2d::CCMenuItemSprite *, CPyMenuItemSprite, setNormalImage, (cocos2d::CCNode *)p->getCCObject());
		return 0;
	}
	PYCLASS_GET_IMPL(CPyMenuItemSprite, SelectedImage)
	{
		CC_METHOD_WRAPPER_GETER(cocos2d::CCMenuItemSprite *, CPyMenuItemSprite, getSelectedImage, cocos2d::CCNode *);
		IWrapper *wrap = dynamic_cast<IWrapper *>(v);
		PyObject *p = Py_None;
		if(wrap)
		{
			p = CPyCCObject::create_object(wrap->GetPythonType(), v);
		}else
			p = (PyObject *)CPyCCObject::create<CPyCCObject>(v);
		return p;
	}
	PYCLASS_SET_IMPL(CPyMenuItemSprite, SelectedImage)
	{
		CPyCCObject *p = (CPyCCObject *)pyValue;
		IWrapper *wrap = dynamic_cast<IWrapper *>(p->getCCObject());
		if(!wrap)
			return 0;
			CC_METHOD_WRAPPER_SETER_RINT(cocos2d::CCMenuItemSprite *, CPyMenuItemSprite, setSelectedImage, (cocos2d::CCNode *)p->getCCObject());
		return 0;
	}
	PYCLASS_GET_IMPL(CPyMenuItemSprite, DisabledImage)
	{
		CC_METHOD_WRAPPER_GETER(cocos2d::CCMenuItemSprite *, CPyMenuItemSprite, getDisabledImage, cocos2d::CCNode *);
		IWrapper *wrap = dynamic_cast<IWrapper *>(v);
		PyObject *p = Py_None;
		if(wrap)
		{
			p = CPyCCObject::create_object(wrap->GetPythonType(), v);
		}else
			p = (PyObject *)CPyCCObject::create<CPyCCObject>(v);
		return p;
	}
	PYCLASS_SET_IMPL(CPyMenuItemSprite, DisabledImage)
	{
		CPyCCObject *p = (CPyCCObject *)pyValue;
		IWrapper *wrap = dynamic_cast<IWrapper *>(p->getCCObject());
		if(!wrap)
			return 0;
			CC_METHOD_WRAPPER_SETER_RINT(cocos2d::CCMenuItemSprite *, CPyMenuItemSprite, setDisabledImage, (cocos2d::CCNode *)p->getCCObject());
		return 0;
	}
	
	int CPyMenuItemSprite::__init__(CPyMenuItemSprite *pySelf, PyObject *pyArgs, PyObject *pyKW)
	{
		if( !pyArgs )
			return 0;
		static char* kwlist[] = {"normalSprite", "selectedSprite", "disabledSprite", "func", NULL};
		PyObject *pynormalSprite = NULL;
		PyObject *pyselectedSprite = NULL;
		PyObject *pydisabledSprite = NULL;
		PyObject *func = NULL;
		if(!PyArg_ParseTupleAndKeywords(pyArgs,pyKW,"OO|OO",kwlist, &pynormalSprite, &pyselectedSprite, &pydisabledSprite, &func))
			return 0;
		
		CPyCCObject *normalSprite = (CPyCCObject *)pynormalSprite;
		cocos2d::CCSprite *cc_normalSprite = dynamic_cast<cocos2d::CCSprite *>(normalSprite->getCCObject());
		if(!cc_normalSprite)
			return 0;
		
		CPyCCObject *selectedSprite = (CPyCCObject *)pyselectedSprite;
		cocos2d::CCSprite *cc_selectedSprite = dynamic_cast<cocos2d::CCSprite *>(selectedSprite->getCCObject());
		if(!cc_selectedSprite)
			return 0;
		
		CPyCCObject *disabledSprite = (CPyCCObject *)pydisabledSprite;
		cocos2d::CCSprite *cc_disabledSprite = NULL;
		if(disabledSprite)
		{
			cc_disabledSprite = dynamic_cast<cocos2d::CCSprite *>(disabledSprite->getCCObject());
		}

		if(func && !PyCallable_Check(func))
			return 0;

		cocos2d::CCMenuItemSprite *item = dynamic_cast<cocos2d::CCMenuItemSprite *>(pySelf->getCCObject());
		if(!item)
			return 0;
		if(func)
		{
			pySelf->setFn(func, false);
			item->initWithNormalSprite(cc_normalSprite, cc_selectedSprite, cc_disabledSprite, item, __menu_selector(__CCMenuItemSpriteWrapper::OnClick));
		}else
			item->initWithNormalSprite(cc_normalSprite, cc_selectedSprite, cc_disabledSprite, NULL, NULL);
		return 0;
	}
	//////////////////////////////////////////////////////////	
	CC_MENUITEM_WRAPPER_IMPL(CCMenuItemImage, CPyMenuItemImage)

	PYCLASS_INIT_AND_BASE(CPyMenuItemImage, CPyMenuItemSprite, "CCMenuItemImage", "Python CCMenuItemImage Object");
	PYCLASS_BEGIN_METHOD_DEF(CPyMenuItemImage)
	PYCLASS_END_METHOD_DEF(CPyMenuItemImage)
	PYCLASS_BEGIN_GETSET_DEF(CPyMenuItemImage)
	PYCLASS_ADD_SET(CPyMenuItemImage, NormalSpriteFrame)
    PYCLASS_ADD_SET(CPyMenuItemImage, SelectedSpriteFrame)
    PYCLASS_ADD_SET(CPyMenuItemImage, DisabledSpriteFrame)
	PYCLASS_END_GETSET_DEF(CPyMenuItemImage)
	PYCLASS_IMP_INTERFACE_NEW(CPyMenuItemImage)

	PYCLASS_SET_IMPL(CPyMenuItemImage, NormalSpriteFrame)
	{
		CPyCCObject *p = (CPyCCObject *)pyValue;
		CC_METHOD_WRAPPER_SETER_RINT(cocos2d::CCMenuItemImage *, CPyMenuItemImage, setNormalSpriteFrame, (cocos2d::CCSpriteFrame *)p->getCCObject());
		return 0;
	}
	PYCLASS_SET_IMPL(CPyMenuItemImage, SelectedSpriteFrame)
	{
		CPyCCObject *p = (CPyCCObject *)pyValue;
		CC_METHOD_WRAPPER_SETER_RINT(cocos2d::CCMenuItemImage *, CPyMenuItemImage, setSelectedSpriteFrame, (cocos2d::CCSpriteFrame *)p->getCCObject());
		return 0;
	}
	PYCLASS_SET_IMPL(CPyMenuItemImage, DisabledSpriteFrame)
	{
		CPyCCObject *p = (CPyCCObject *)pyValue;
		CC_METHOD_WRAPPER_SETER_RINT(cocos2d::CCMenuItemImage *, CPyMenuItemImage, setDisabledSpriteFrame, (cocos2d::CCSpriteFrame *)p->getCCObject());
		return 0;
	}
	
	int CPyMenuItemImage::__init__(CPyMenuItemImage *pySelf, PyObject *pyArgs, PyObject *pyKW)
	{
		if( !pyArgs )
			return 0;
		static char* kwlist[] = {"normalImage", "selectedImage", "disabledImage", "func", "fromCache", NULL};
		char *s_normal = NULL;
		char *s_selected = NULL;
		char *s_disabled = NULL;
		PyObject *func = NULL;
		PyObject *pyfromCache = NULL;
		if(!PyArg_ParseTupleAndKeywords(pyArgs,pyKW,"ss|sOO",kwlist, &s_normal, &s_selected, &s_disabled, &func, &pyfromCache))
			return 0;
		bool fromCache = pyfromCache == Py_True;

		if(func && !PyCallable_Check(func))
			return 0;

		cocos2d::CCMenuItemImage *item = dynamic_cast<cocos2d::CCMenuItemImage *>(pySelf->getCCObject());
		if(!item)
			return 0;
		if(func)
			pySelf->setFn(func, false);
		if(fromCache)
		{
			cocos2d::CCSpriteFrame *frm = !s_normal ? NULL : cocos2d::CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(s_normal);
			if(frm)
				item->setNormalSpriteFrame(frm);
			frm = !s_selected ? NULL : cocos2d::CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(s_selected);
			if(frm)
				item->setSelectedSpriteFrame(frm);
			frm = !s_disabled ? NULL : cocos2d::CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(s_disabled);
			if(frm)
				item->setDisabledSpriteFrame(frm);
			if(func)
				item->setTarget(item, __menu_selector(__CCMenuItemImageWrapper::OnClick));
		}
		else
		{
			if(func)
			{
				item->initWithNormalImage(s_normal, s_selected, s_disabled, item, __menu_selector(__CCMenuItemImageWrapper::OnClick));
			}else
				item->initWithNormalImage(s_normal, s_selected, s_disabled, NULL, NULL);
		}
		return 0;
	}
	
	void CPyMenuItemImage::__del__(CPyMenuItemImage *self)
	{
		self->freeFn();
		self->ob_type->tp_free(self);
	}
	//////////////////////////////////////////////////////////	
	CC_MENUITEM_WRAPPER_IMPL(CCMenuItemToggle, CPyMenuItemToggle)	

	PYCLASS_INIT_AND_BASE(CPyMenuItemToggle, CPyMenuItem, "CCMenuItemToggle", "Python CCMenuItemToggle Object");
	PYCLASS_BEGIN_METHOD_DEF(CPyMenuItemToggle)
		PYCLASS_ADD_METHOD(CPyMenuItemToggle, initWithItem)
		PYCLASS_ADD_METHOD(CPyMenuItemToggle, addSubItem)
	PYCLASS_END_METHOD_DEF(CPyMenuItemToggle)
	PYCLASS_BEGIN_GETSET_DEF(CPyMenuItemToggle)
		PYCLASS_ADD_GET(CPyMenuItemToggle, selectedItem)
		PYCLASS_ADD_GETSET(CPyMenuItemToggle, SelectedIndex)
		PYCLASS_ADD_GETSET(CPyMenuItemToggle, SubItems)
	PYCLASS_END_GETSET_DEF(CPyMenuItemToggle)
	PYCLASS_IMP_INTERFACE_NEW(CPyMenuItemToggle)

	void CPyMenuItemToggle::__del__(CPyMenuItemToggle *self)
	{
		self->freeFn();
		self->ob_type->tp_free(self);
	}
		
	int CPyMenuItemToggle::__init__(CPyMenuItemToggle *pySelf, PyObject *pyArgs, PyObject *pyKW)
	{
		if( !pyArgs )
			return 0;
		static char* kwlist[] = {"items", "func", NULL};
		PyObject *items = NULL;
		PyObject *func = NULL;
		if(!PyArg_ParseTupleAndKeywords(pyArgs,pyKW,"|OO",kwlist, &items, &func))
			return 0;
		if(func && !PyCallable_Check(func))
			return 0;
		cocos2d::CCMenuItemToggle *item = dynamic_cast<cocos2d::CCMenuItemToggle *>(pySelf->getCCObject());
		if(!item)
			return 0;
		if(func)
		{
			pySelf->setFn(func, false);
			item->setTarget(item, __menu_selector(__CCMenuItemToggleWrapper::OnClick));
		}
		if(items && PySequence_Check(items))
		{
			Py_ssize_t s = PySequence_Size(items);
			for(Py_ssize_t i = 0; i < s; i ++)
			{
				CPyCCObject *py = (CPyCCObject *)PySequence_GetItem(items, i);
				cocos2d::CCMenuItem *sitem = dynamic_cast<cocos2d::CCMenuItem *>(py->getCCObject());
				if(sitem)
					item->addSubItem(sitem);
			}
		}
		return 0;
	}
	PYCLASS_METHOD_IMPL(CPyMenuItemToggle, initWithItem)
	{
		PyObject *s = NULL;
		if( !PyArg_ParseTuple(pyArgs, "O", &s) )
			Py_RETURN_FALSE;
		if(!s)
			Py_RETURN_FALSE;
		cocos2d::CCMenuItemToggle *item = dynamic_cast<cocos2d::CCMenuItemToggle *>(pySelf->getCCObject());
		if(!item)
			Py_RETURN_NONE;
		CPyCCObject *py = (CPyCCObject *)s;
		cocos2d::CCMenuItem *sitem = dynamic_cast<cocos2d::CCMenuItem *>(py->getCCObject());
		bool v = false;
		if(sitem)
			v = item->initWithItem(sitem);
		Py_RETURN_BOOL(v);
	}

	PYCLASS_METHOD_IMPL(CPyMenuItemToggle, addSubItem)
	{
		PyObject *s = NULL;
		if( !PyArg_ParseTuple(pyArgs, "O", &s) )
			Py_RETURN_NONE;
		if(!s)
			Py_RETURN_NONE;
		cocos2d::CCMenuItemToggle *item = dynamic_cast<cocos2d::CCMenuItemToggle *>(pySelf->getCCObject());
		if(!item)
			Py_RETURN_NONE;
		CPyCCObject *py = (CPyCCObject *)s;
		cocos2d::CCMenuItem *sitem = dynamic_cast<cocos2d::CCMenuItem *>(py->getCCObject());
		if(sitem)
			item->addSubItem(sitem);
		Py_RETURN_NONE;
	}

	PYCLASS_GET_IMPL(CPyMenuItemToggle, selectedItem)
	{
		cocos2d::CCMenuItemToggle *item = dynamic_cast<cocos2d::CCMenuItemToggle *>(pySelf->getCCObject());
		if(!item)
			Py_RETURN_NONE;
		cocos2d::CCMenuItem *sitem = item->selectedItem();
		if(!sitem)
			Py_RETURN_NONE;
		return (PyObject *)CPyCCObject::create<CPyMenuItem>(sitem);
	}

	PYCLASS_GET_IMPL(CPyMenuItemToggle, SelectedIndex)
	{
		cocos2d::CCMenuItemToggle *item = dynamic_cast<cocos2d::CCMenuItemToggle *>(pySelf->getCCObject());
		if(!item)
			Py_RETURN_NONE;
		unsigned int i = item->getSelectedIndex();
		return Py_BuildValue("I", i);
	}

	PYCLASS_SET_IMPL(CPyMenuItemToggle, SelectedIndex)
	{
		cocos2d::CCMenuItemToggle *item = dynamic_cast<cocos2d::CCMenuItemToggle *>(pySelf->getCCObject());
		if(!item)
			return 0;
		item->setSelectedIndex(PyLong_AsUnsignedLong(pyValue));
		return 0;
	}
	
	PYCLASS_GET_IMPL(CPyMenuItemToggle, SubItems)
	{
		cocos2d::CCMenuItemToggle *item = dynamic_cast<cocos2d::CCMenuItemToggle *>(pySelf->getCCObject());
		if(!item)
			Py_RETURN_NONE;
		PyObject *pyList = CCPyDataConvert::CCArrayToPyList(item->getSubItems());
		return pyList;
	}

	PYCLASS_SET_IMPL(CPyMenuItemToggle, SubItems)
	{
		cocos2d::CCMenuItemToggle *item = dynamic_cast<cocos2d::CCMenuItemToggle *>(pySelf->getCCObject());
		if(!item)
			return 0;
		if(!PySequence_Check(pyValue))
			return 0;
		cocos2d::CCArray *arr = CCPyDataConvert::CCArrayFromPyList(pyValue);
		item->setSubItems(arr);
		return 0;
	}
	//////////////////////////////////////////////////////////

NS_CCPY_END

#endif